﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace PjMediaStarter
{
    class MyPjMedia
    {

        [System.Runtime.InteropServices.DllImportAttribute("PjLibDLL.dll", EntryPoint = "start", CharSet = CharSet.Auto)]
        private static extern int start( [MarshalAs(UnmanagedType.LPWStr)] StringBuilder ip,
                                         [MarshalAs(UnmanagedType.LPWStr)] StringBuilder port,
                                         [MarshalAs(UnmanagedType.LPWStr)] StringBuilder codec,
                                         [MarshalAs(UnmanagedType.LPWStr)] StringBuilder key_TX,
                                         [MarshalAs(UnmanagedType.LPWStr)] StringBuilder key_RX);

        [DllImport("PjLibDLL.dll", EntryPoint = "stop")]
        private static extern int stop();

        /// <summary>
        /// Wrapping for DLL function start() used to start pjmedia.
        /// </summary>
        /// <param name="url">Ip to connect</param>
        /// <param name="porta">Port to connect</param>
        /// <param name="codec">Codec used</param>
        /// <param name="key_TX">Transmitting key</param>
        /// <param name="key_RX">Reciving key</param>
        /// <returns>return 0 for success</returns>
        public static int StartPjMedia( StringBuilder url,
                                        StringBuilder porta,
                                        StringBuilder codec,
                                        StringBuilder key_TX,
                                        StringBuilder key_RX)
        {
            int result = start(url, porta, codec, key_TX, key_RX);
            return result;
        }

        /// <summary>
        /// Wrapping for DLL function stop() used to stop pjmedia.
        /// </summary>
        /// <returns>return 0 for success</returns>
        public static int StopPjMedia()
        {
            int result = stop();
            return result;
        }
    }
}
